﻿using System;
using Myotragus.Data.Util;
using NUnit.Framework;

namespace Myotragus.Data.Tests.Tests.Utils
{
	[TestFixture]
	public class ExecutionHelperFixtures
	{
		[Test]
		public void ExceptionCreatorValidation()
		{
			Assert.Throws<Exception>(() =>
				ExecutionHelper.CreateException<ExceptionWrong>());
			Assert.DoesNotThrow(() =>
				ExecutionHelper.CreateException<ExceptionNone>());
			Assert.DoesNotThrow(() =>
				ExecutionHelper.CreateException<ExceptionMessage>());
			Assert.DoesNotThrow(() =>
				ExecutionHelper.CreateException<ExceptionMessageAndInner>());
		}

		[Test]
		public void ExceptionCreatorResults()
		{
			var inner = new Exception();

			var ex1 = ExecutionHelper.CreateException<ExceptionNone>(inner, "Message: {0}", 1);
			Assert.AreEqual(null, ex1.InnerException);

			var ex2 = ExecutionHelper.CreateException<ExceptionMessage>(inner, "Message: {0}", 1);
			Assert.AreEqual(null, ex2.InnerException);
			Assert.AreEqual("Message: 1", ex2.Message);

			var ex3 = ExecutionHelper.CreateException<ExceptionMessageAndInner>(inner, "Message: {0}", 1);
			Assert.AreEqual(inner, ex3.InnerException);
			Assert.AreEqual("Message: 1", ex3.Message);
		}
	}
}